package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author 郭腾高
 * @Date 2024/9/27 15:35
 */
@Mapper
public interface OrderMapper {



    /*插入订单信息*/
    void insert(Orders orders);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
     /*更新订单状态*/
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);
    /*查询所有订单id*/
    @Select("select id from orders")
    List<Long> getId();
    /*查询历史订单*/
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /*根据id查询订单信息*/
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);
    /*查询各个状态的订单数量统计*/
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    //定时任务调度
    @Select("select * from orders where status=#{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime time);
   //当天营业额
    Double getDayAmount(Map map);
    //订单数量
    Integer getOrderNumber(LocalDateTime begin, LocalDateTime end, Integer status);
    /*订单排名前10*/
    List<GoodsSalesDTO> top10(LocalDateTime begin, LocalDateTime end);
    /**
     * 根据动态条件统计订单数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);


}

